#!/usr/bin/perl
#save_atalk.cgi

require './protocolman-lib.pl';

my (%servconf, $servline, $error_msg);

&ReadParse();

&error_setup($text{'save_afp_error'});

#default timeout and maxsession
$in{'afp_timeout'} = 30 unless($in{'afp_timeout'});
$in{'afp_session'} = 20 unless($in{'afp_session'});

&foreign_require("shareman", "shareman-lib.pl");
$error_msg = &foreign_call("shareman", "check_input_not_integer", $in{'afp_timeout'});
if($error_msg || $in{'afp_timeout'} == 0)
{
	&nas_syslog("protocolman", "naslog_warning", $text{'naslog_ev_afp_session'}, $text{'naslog_msg_afp_session'});
	&error($text{'err_msg_afp_timeout'});
}

&foreign_require("shareman", "shareman-lib.pl");
$error_msg = &foreign_call("shareman", "check_input_not_integer", $in{'afp_session'});
if($error_msg || $in{'afp_session'} == 0)
{
	&nas_syslog("protocolman", "naslog_warning", $text{'naslog_ev_afp_timeout'}, $text{'naslog_msg_afp_timeout'});
	&error($text{'err_msg_afp_session'});
}

if(-f $config{'bondinglock'})
{
    &error($text{'err_msg_atalk_bonding'});
}

if($in{'afp_allowguest'})
{	
	$servconf{'uamlist'} = '-uamlist uams_guest.so,uams_clrtxt.so,uams_dhx.so';
}
else
{
	$servconf{'uamlist'} = '-uamlist uams_clrtxt.so,uams_dhx.so';
}

$in{'afp_timeout'} *= 2;
$in{'afp_session'} += 0;

$servconf{'timeout'} = '-timeout ' . $in{'afp_timeout'};

&foreign_require("netatalk", "netapple-lib.pl");
$servline = &foreign_call("netatalk", "ez_afp_chg_servline", \%servconf);
&foreign_call("netatalk", "ez_save_afpserver", $servline);
&foreign_call("netatalk", "ez_save_maxsessions", $in{'afp_session'});

`$config{'afp_service'} restart`;

&redirect("index.cgi");
